<?php
/*
 * @ https://EasyToYou.eu - IonCube v11 Decoder Online
 * @ PHP 7.2 & 7.3
 * @ Decoder version: 1.1.6
 * @ Release: 10/08/2022
 */

// Decoded file for php version 71.
namespace app\massage\model;

class AdminWater extends \app\BaseModel
{
    protected $name = "massage_admin_water";
    public function dataAdd($data)
    {
        $res = $this->insert($data);
        return $res;
    }
    public function dataUpdate($dis, $data)
    {
        $res = $this->where($dis)->update($data);
        return $res;
    }
    public function dataList($dis, $page)
    {
        $data = $this->where($dis)->order("status desc,id desc")->paginate($page)->toArray();
        return $data;
    }
    public function dataInfo($dis)
    {
        $data = $this->where($dis)->find();
        return !empty($data) ? $data->toArray() : [];
    }
    public function updateCash($uniacid, $admin_id, $cash, $is_add)
    {
        $is_add = $is_add == 1 ? $is_add : -1;
        $admin_model = new Admin();
        $admin_info = $admin_model->dataInfo(["id" => $admin_id]);
        if(empty($admin_info)) {
            return true;
        }
        $admin_cash = $admin_info["cash"];
        if(!empty($last_record) && round($last_record->after_cash, 2) != round($admin_cash, 2)) {
            return 0;
        }
        $true_cash = $is_add == 1 ? $cash : $cash * -1;
        if($true_cash == 0) {
            return true;
        }
        $res = $admin_model->where(["id" => $admin_id, "cash" => $admin_info["cash"]])->update(["cash" => \think\facade\Db::Raw("cash+" . $true_cash)]);
        if($res == 0) {
            return 0;
        }
        $insert = ["uniacid" => $uniacid, "admin_id" => $admin_id, "before_cash" => $admin_cash, "after_cash" => $admin_cash + $true_cash, "cash" => $cash, "res" => $res, "create_time" => time(), "add" => $is_add];
        $res = $this->insert($insert);
        if($res == 0) {
            return 0;
        }
        return $res;
    }
}

?>